//
// Created by aaa on 2025/7/10.
//

#include<bits/stdc++.h>

using namespace std;
const int N = 1e3 + 10;

int a[N][N];
int dp[N][N],p[N][N];
int n;

//线性dp 数字三角形
//5
//7
//3 8
//8 1 0
//2 7 4 4
//4 5 2 6 5
int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= i;j++) cin >> a[i][j];
    }

    for(int i = n;i >= 1;i--){
        for(int j = 1;j <= i;j++){
            if(i == n) dp[i][j] = a[i][j];
            else {
                if(dp[i+1][j] > dp[i+1][j+1]){
                    dp[i][j] = a[i][j] + dp[i+1][j];
                    p[i][j] = 0;
                }else{
                    dp[i][j] = a[i][j] + dp[i+1][j+1];
                    p[i][j] = 1;
                }
            }
        }
    }

    cout << dp[1][1] << endl;


    for(int i = 1,j = 1;i <= n;i++){
        if(i == n) cout << a[i][j];
        else cout << a[i][j] << "->";
        j += p[i][j];
    }

    return 0;
}